#ifndef COLOR_H
#define COLOR_H


#include "vec3.h"
#include"interval.h"



using color = vec3;


inline double linear_to_gamma(double linear) {
	if (linear > 0) {
		return std::sqrt(linear);
	}
	return 0;
}


void write_color(std::ostream& out, const color& _color) {
	auto r = _color.x();
	auto g = _color.y();
	auto b = _color.z();

	r = linear_to_gamma(r);
	g = linear_to_gamma(g);
	b = linear_to_gamma(b);


	//range [0,1] to [0,255]
	static const interval intensity(0.000, 0.999);

	int rb = int(256 * intensity.clamp(r));
	int gb = int(256 * intensity.clamp(g));
	int bb = int(256 * intensity.clamp(b));

	out << rb << ' ' << gb << ' ' << bb<<'\n';
}













#endif // !COLOR_H

